// sc 从0开始，ec不包含
export function setInlineStyle_inlined({ curCell, sc, ec, styleObj }) {
  const curSpanArr = curCell?.ct?.s
  if (!curSpanArr) {
    return
  }
  // 构造开始
  if (ec <= sc) {
    return curSpanArr
  }
  let resultArr = []
  let newSc = sc
  let newEc = ec

  // curSpanArr = [{ v: '用户' }, { fc: 'rgb(255, 0, 0)', v: '觉得' }, { v: '很好' }]
  for (let i = 0; i < curSpanArr.length; i++) {
    const curSpan = curSpanArr[i]
    const curStr = curSpanArr[i]?.v ?? ''
    const len = curStr.length
    if (len <= 0) {
      // 长度为空时，这个对象不合格，不push
      continue
    }
    if (newSc >= len) {
      newSc -= len
      newEc -= len
      resultArr.push(curSpan)
      continue
    }

    // 针对【开始位置计算完毕，结束位置在后面的对象】的情况
    if (newSc < 0) {
      if (newEc < 0) {
        let obj = { ...curSpan }
        resultArr.push(obj)
        continue
      }
      const preObj = resultArr.pop()
      preObj.v = preObj.v + curStr.slice(0, newEc)
      resultArr.push(preObj)

      if (newEc < len) {
        let obj = { ...$.extend(true, {}, curSpan), v: curStr.slice(newEc) }
        resultArr.push(obj)
      }
      newEc -= len
      continue
    }
    // 针对【开始位置计算完毕，结束位置在后面的对象】的情况 END

    if (newSc > 0 && newSc < len) {
      let firstObj = { ...$.extend(true, {}, curSpan), v: curStr.slice(0, newSc) }
      resultArr.push(firstObj)
    }

    let secondObj = { ...styleObj, v: curStr.slice(newSc, newEc) }
    resultArr.push(secondObj)

    if (newEc < len) {
      let threeObj = { ...$.extend(true, {}, curSpan), v: curStr.slice(newEc) }
      // 针对结束位置在当前节点，这时就会有第三个对象出现
      resultArr.push(threeObj)
    }
    newSc -= len
    newEc -= len
  }
  console.log(resultArr, '设置的inlineString')
  return resultArr
}
export function setInlineStyle_pure({ curCell, sc, ec, styleObj }) {
  const str = curCell?.m
  const len = str.length
  if (len <= 0) {
    return
  }

  if (ec <= sc) {
    return
  }

  let resultArr = []

  if (sc > 0 && sc < len) {
    let firstObj = { v: str.slice(0, sc) }
    resultArr.push(firstObj)
  }

  let secondObj = { ...styleObj, v: str.slice(sc, ec) }
  resultArr.push(secondObj)

  let threeObj = { v: str.slice(ec) }
  if (ec < len) {
    resultArr.push(threeObj)
  }
  return resultArr
}
